package org.ysu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ysu.common.JsonResult;
import org.ysu.mapper.CCadreMapper;
import org.ysu.pojo.CCadre;
import org.ysu.pojo.User;
import org.ysu.service.CCadreService;
import org.ysu.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private CCadreService cCadreService;
    @GetMapping("/id")
    public User getUserById(Integer id){
        return userService.getById(id);
    }
    @GetMapping("/get")
    public List<User> getUsers(String name){
        return userService.getUsers(name);
    }

    /***
     * 判断登录信息
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/login")
    public JsonResult login(@RequestParam("username") String username, @RequestParam("password") String password){
        User u =userService.checkUser(username,password);
        JsonResult result;
        if(u.getId()!=-1){
            result = new JsonResult<>(1,"success",u);
        }else{
            result = new JsonResult<>(0,"fail","");
        }
        return result;
    }

    @GetMapping("/selectByIdNumber/{idNumber}")
    public CCadre selectByIdNumber(@PathVariable("idNumber") String idNumber){
        System.out.println("idNumber:"+idNumber);
        CCadre id=cCadreService.selectByIdNumber(idNumber);
        return id;
    }
}
